package keqiang.com.kq_flutter_widgets;

import androidx.annotation.NonNull;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.EventChannel;
import keqiang.com.kq_flutter_widgets.channel.NativeScanChannel;

/**
 * KqFlutterWidgetsPlugin
 */
public class KqFlutterWidgetsPlugin implements FlutterPlugin, ActivityAware {
    
    private NativeScanChannel mScanChannel;
    
    @Override
    public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
        mScanChannel = new NativeScanChannel(flutterPluginBinding.getBinaryMessenger());
    }
    
    @Override
    public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
        mScanChannel.setMethodCallHandler(null);
    }
    
    @Override
    public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
        if (mScanChannel != null) {
            mScanChannel.setContext(binding.getActivity());
        }
    }
    
    @Override
    public void onDetachedFromActivityForConfigChanges() {
    }
    
    @Override
    public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
    }
    
    @Override
    public void onDetachedFromActivity() {
    }
}
